const { ccclass, property } = cc._decorator;
@ccclass
export default class PolygonButton extends cc.Component {

    @property(cc.Boolean) Interactable: boolean = true
    onEnable() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.TouchStart, this)
        for (let index = 0; index < this.node.getComponent(cc.PolygonCollider).points.length; index++) {
            this.TouchPoints[index] = this.node.getComponent(cc.PolygonCollider).points[index].add(this.node.convertToWorldSpaceAR(cc.Vec2.ZERO_R))
        }
    }
    onDisable() {
        this.node.off(cc.Node.EventType.TOUCH_START, this.TouchStart, this);
    }
    private TouchPoints: cc.Vec2[] = []
    private TouchStart(touch: cc.Event.EventTouch) {
        if (cc.Intersection.pointInPolygon(touch.getLocation(), this.TouchPoints)) {
            // @ts-ignore
            this.node._touchListener.setSwallowTouches(true)
            if (this.Interactable) {
                console.log("在");
            }
        } else {
            // @ts-ignore
            this.node._touchListener.setSwallowTouches(false)
            console.log("不在");
        }

    }
}
